package com.wsapi.core;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * 在系统运行中，作为管理平台，模块和权限的基础数据缓存
 *
 * @author yangyan
 *
 */
public class Platforms {

    final static List<Platform> LIST = new ArrayList<Platform>();
    final static Map<String, Platform> PLATFORMS = new HashMap<String, Platform>();

    public static void register(Platform platform) {
        LIST.add(platform);
        PLATFORMS.put(platform.getId(), platform);
    }

    public static void unregister(Platform platform) {
        LIST.remove(platform);
        PLATFORMS.remove(platform);
    }

    public static void unregister(String id) {
        Platform remove = PLATFORMS.remove(id);
        if (remove != null) {
            LIST.remove(remove);
        }
    }

    public static List<Platform> getPlatforms() {
        return LIST;
    }
}
